# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=opencolorio

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=689.63c6bde
pkgrel=1
pkgdesc="A color management framework for visual effects and animation (mingw-w64)"
arch=('any')
url="http://opencolorio.org"
license=('BSD')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
    "${MINGW_PACKAGE_PREFIX}-glew"
    "${MINGW_PACKAGE_PREFIX}-freeglut"
    "${MINGW_PACKAGE_PREFIX}-lcms2"
    "${MINGW_PACKAGE_PREFIX}-python2"
    "${MINGW_PACKAGE_PREFIX}-tinyxml")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
      "${MINGW_PACKAGE_PREFIX}-yaml-cpp0.3"
      "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' 'buildflags')
source=("${_realname}"::"git+https://github.com/imageworks/OpenColorIO.git"
    #http://github.com/imageworks/OpenColorIO/tarball/v$pkgver
    mingw-w64.patch
    fix-redefinitions.patch)
sha1sums=('SKIP'
          '19cdc7480f51df84f3280b35a8d0e514f49874c5'
          '8e4eaca025b110ea18036ccf71e0f5e1e8e17f5b')

pkgver() {
  cd "$srcdir/$_realname"
  printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd $_realname
  patch -p1 -i ${srcdir}/mingw-w64.patch
  patch -p1 -i ${srcdir}/fix-redefinitions.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  #CFLAGS+=" -I${MINGW_PREFIX}/include/python2.7"
  #CXXFLAGS+=" -I${MINGW_PREFIX}/include/python2.7"
  cd $_realname 
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DGLEW_INCLUDES=${PREFIX_DEPS}/include \
    -DGLEW_LIBRARIES=${PREFIX_DEPS}/lib/libglew32.dll.a \
    -DUSE_EXTERNAL_TINYXML=ON \
    -DUSE_EXTERNAL_YAML=ON \
    -DUSE_EXTERNAL_LCMS=ON \
    -DOCIO_USE_BOOST_PTR=ON \
    -DOCIO_BUILD_PYGLUE=OFF \
    -DOCIO_BUILD_TRUELIGHT=OFF \
    .
    #-DPYTHON=${PREFIX_DEPS}/bin/python2.exe \
    #-DPYTHON_LIBRARIES=${PREFIX_DEPS}/lib/libpython2.7.dll.a \
    #-DPYTHON_HEADER=${PREFIX_DEPS}/include/python2.7/Python.h \
    #-DPYTHON_INCLUDE_DIRS=${PREFIX_DEPS}/include/python2.7 \
  make 
}

package() {
  cd "$_realname"
  make install
  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE

  cd ${pkgdir}${MINGW_PREFIX}
  export PREFIX_WIN=`pwd -W`
  mkdir -p bin
  mv lib/*.dll bin/
  for ff in lib/pkgconfig/*.pc; do
    sed -i "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" $ff
  done
}
